package com.yigang.controller;

import java.text.ParseException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yigang.entity.ImgAndProduct;
import com.yigang.entity.OrderAndProduct;
import com.yigang.entity.Product;
import com.yigang.entity.User;
import com.yigang.service.ProductService;
import com.yigang.utils.ResultUtil;
/**
 * @author 陈佳祥
 *商品管理
 *增删改查    上架下架
 *是否推荐  管理
 */
@Controller
@RequestMapping("/product")
public class ProductController {

	@Autowired
	private ProductService productService;
	//椤甸潰閲嶅畾鍚�
	@RequestMapping("productList")
	public String productList() {
		return "jsp/product/productList";
	}
	@RequestMapping("addProduct")
	public String addProduct() {
		return "jsp/product/addProduct";
	}
	
	@RequestMapping("editProduct/{id}")
	public String editProduct(@PathVariable("id") int id, HttpSession session) {
		Product product = productService.selectProductById(id);
	
		session.setAttribute("product", product);
		return "jsp/product/editProduct";
	}
	@RequestMapping("imgAndProduct")
	public String theorderDetails(ImgAndProduct imgAndProduct, HttpSession session) {
		ImgAndProduct productImg = productService.selectImgAndProduct(imgAndProduct);
	
		session.setAttribute("productImg", productImg);
		return "jsp/product/productImgList";
	}
	
	@RequestMapping("getProductImg")
	@ResponseBody
	public ResultUtil getTheorderDetails(Integer page, Integer limit, ImgAndProduct imgAndProduct) {

	
		
		return productService.getProductImg(page, limit, imgAndProduct);
	}
	//澧炲垹鏌ユ敼鏂规硶
	@RequestMapping("insertProduct")
	@ResponseBody
	public ResultUtil insertProduct(Product record) {
		productService.insertSelective(record);
		return ResultUtil.ok();

	}

	@RequestMapping("deleteProductById")
	@ResponseBody
	public ResultUtil deleteProductById(int id) {
		
		return productService.deleteByPrimaryKey(id);
	}

	@RequestMapping("getProductList")
	@ResponseBody
	public ResultUtil getProductList(Integer page, Integer limit, Product record) {

		return productService.selectProductList(page, limit, record);
	}

	@RequestMapping("updateProduct")
	@ResponseBody
	public ResultUtil updateProduct(Product record) throws ParseException {
		
		return productService.updateByPrimaryKeySelective(record);
	}
	@RequestMapping("updateProductStatusById")
	@ResponseBody
	public ResultUtil updateProductStatusById(int productId, int productRecommend) {
		return productService.updateProductStatusById(productId, productRecommend);
	}
	@RequestMapping("updateProductShelfById")
	@ResponseBody
	public ResultUtil updateProductShelfById(int productId, int productShelf) {
		return productService.updateProductShelfById(productId, productShelf);
	}

}
